package com.web;

import java.util.HashMap;

public class MemberManageAction extends ActionSupport{	
	protected IMemberService memberService;
	protected IProductService productService;
	protected ICustomerService customerService;
	protected IApplyService applyService;
	
	private Integer userId;
	private Integer productId;
	private Integer applyId;
	private String openId;
	private String name;
	private String special;
	private String productNumber;
	private HashMap<String, Object> resultMap = new HashMap<String, Object>();
	
	// 前端接口
	
	/*
	 *  客户信息
	 *  @param openId
	 */
	public String userInfo() throws Exception{
		ActionContext ctx = ActionContext.getContext();
		String openId = (String) ctx.get("openId");
		Member member = memeberService.getMember(openId);
		ctx.put("member", member);
		return "memberInfo";
	}
	/*
	 *  更新客户信息
	 *  @param openId
	 */
	public String updateMemberInfo() throws Exception{
		ActionContext ctx = ActionContext.getContext();
		String openId = (String) ctx.get("openId");
		MemberWeiXin curMember = MemberService.getMemberInfo(openId);
		Member member = memberService.getMember(openId);
		member.setName(curMember.getNickname());
		member.setCity(curMember.getCity());
		member.setHeadImgUrl(curMember.getHeadimgurl());
		member.setProvince(curMember.getProvince());
		member.setSex(curMember.getSex()==1?"男":"女");
		memberService.updateMember(member);
		ctx.put("member", member);
		return "memberInfo";
	}
	
	/*
	 * 查看产品信息
	 */
	public String productInfo() throws Exception{
		ActionContext ctx = ActionContext.getContext();
		String openId = (String) ctx.get("openId");
		ctx.put("product", memberService.getmember(openId).getproduct());
		return "productInfo";
	}
	
	/*
	 * 查看所有产品
	 */
	public String productList() throws Exception{
		ActionContext ctx = ActionContext.getContext();
		Member member = memberService.getmeber((String)ctx.get("openId"));
		ctx.put("productList", productService.listproduct());
		ctx.put("applysList", applyService.getApply(user));
		ctx.put("inproduct", user.getProduct());
		return "productList";
	}
	
	/*
	 * 申请会员页面
	 * @param openId
	 */
	public String applyManage() throws Exception{
		return "applyManage";
	}
	
	/*
	 * 申请成为会员
	 * @param openId
	 */
	public String applyMember() throws Exception{
		ActionContext ctx = ActionContext.getContext();
		Member member = memberService.getMember((String) ctx.get("openId"));
		resultMap = new HashMap<String, Object>();
		
		if(member == null){
			resultMap.put("status", false);
			resultMap.put("ret", "恭喜你成为会员");
			return SUCCESS;
		}  else if(applyService.waitApply(member)){
			resultMap.put("status", false);
			resultMap.put("ret", "请勿在处理期间重复申请");
			return SUCCESS;
		}
	}
	
	/*
	 * 查看申请结果
	 * @param openId
	 */
	public String applyResult() throws Exception{
		ActionContext ctx = ActionContext.getContext();
		Member member = memberService.getMember((String)ctx.get("openId"));
	}
	
	/*
	 * 删除申请结果
	 * @param applyId
	 */
	public String delApply() throws Exception{
		resultMap = new HashMap<String, Object>();
		
		applyService.delApply(applyId);
		resultMap.put("status", true);
		resultMap.put("ret", "删除成功");
		return SUCCESS;
	}
	
	public void setMemberService(IMemberService memberService) {
		this.memberService = memberService;
	}
	
	public void setproductService(IProductService productService) {
		this.productService = productService;
	}

	public void setApplyService(IApplyService applyService) {
		this.applyService = applyService;
	}

	public Integer getMemberId() {
		return memberId;
	}

	public void setMemberId(Integer memberId) {
		this.memberId = memberId;
	}

	public Integer getproductId() {
		return productId;
	}

	public void setproductId(Integer productId) {
		this.productId = productId;
	}

	public Integer getApplyId() {
		return applyId;
	}

	public void setApplyId(Integer applyId) {
		this.applyId = applyId;
	}

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}


	public HashMap<String, Object> getResultMap() {
		return resultMap;
	}

	public void setResultMap(HashMap<String, Object> resultMap) {
		this.resultMap = resultMap;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getSpecial() {
		return special;
	}

	public void setSpecial(String special) {
		this.special = special;
	}

	public String getProductNumber() {
		return productNumber;
	}

	public void setProductNumber(String productNumber) {
		this.productNumber = productNumber;
	}

	public void setCustomerService(ICustomerService customerService) {
		this.customerService = customerService;
	}
}

